< previous page page_346 next page >

Page 346
C declarations are very similar to Visual Basic declarations, they just look reversed. Where a Visual Basic program might define a Long as follows:
Dim myLong As Long
a C program would define it as:
long myLong;
The type comes first.
Note that all of the C language native data types are in lowercase. One reason you'll want to remember this is that most C programmers use all uppercase names for constants and derived data types (data types that are defined by the programmer and not the language). Keywords, including data types, in the C language are case-sensitive. So where Visual Basic doesn't care if you type in long, Long, or LONG and force the case to match the original declaration, the C language would interpret each of these as different keywords and raise errors when you try to use one that doesn't exist.
Arrays
C language arrays are similar to Visual Basic arrays except that they are less flexible. Square brackets are used to indicate the array; thus:
int A[5];
defines an array of five integers. The valid index values for the array are A[0] through A[4]. Yes, C arrays always start at a base index of 0.
Consider the following character array:
char myString[4];
myString [0] = 'Y';
myString [1] = 'E';
myString [2] = 'S';
myString [3] = 0;
This defines an array of four characters. The final character is the NULL character (value 0). Tutorial 5, "The ByVal Keyword: The Solution to 90 Percent of All API Problems," describes a C language string as an array of characters with a NULL termination character. Sound familiar? This is exactly how C programs deal with stringsas arrays of characters.

 
< previous page page_346 next page >